﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Reflection;
using System.Data;
using Water.Architecture2.IDAL;
using System.Collections;
using System.Web;
using System.Web.UI.WebControls;

namespace Water.Web.Controls
{
    class ObjectHierarchicalDataCollection : IHierarchicalEnumerable
    {

        #region private field

        private object typeInstance;
        private MethodInfo method;
        private string parentPath;
        private DataSet items;
        private string dataIDField;
        private string dataParentIDField;
        private string isLeafField;

        private ParameterCollection _selectParameters;
        private ParameterCollection _rootParameters;

        private HttpContext _context;
        private ObjectHierarchicalDataSource _owner;

        #endregion
          #region Constructors
        public ObjectHierarchicalDataCollection(string dataIDField, string dataParentIDField, string isLeafField, string parentPath, DataSet items, object typeInstance, MethodInfo method, HttpContext context, ObjectHierarchicalDataSource owner, ParameterCollection selectParameters, ParameterCollection rootParameters)
        {
            this.parentPath = parentPath;
            this.items = items;
            this.typeInstance = typeInstance;
            this.method = method;
            this.dataIDField = dataIDField;
            this.dataParentIDField = dataParentIDField;
            this.isLeafField = isLeafField;

            this._context = context;
            this._owner = owner;
            this._selectParameters = selectParameters;
            this._rootParameters = rootParameters;
        }
        #endregion


        #region IHierarchicalEnumerable 成员

        public IHierarchyData GetHierarchyData(object enumeratedItem)
        {
            return new ObjectHierarchyData(this.dataIDField,this.dataParentIDField,this.isLeafField,this.parentPath,(DataRowView)enumeratedItem,this.typeInstance,this.method,_context,_owner,_selectParameters,_rootParameters);
        }

        #endregion

        #region IEnumerable 成员

        public System.Collections.IEnumerator GetEnumerator()
        {
            return this.items.Tables[0].DefaultView.GetEnumerator();
        }

        #endregion
    }
}
